import request from './request'
import { useUserStore } from '../store/modules/user'
import { UploadRawFile } from 'element-plus'
// 商品附件上传
export function proAnnexUpload(fileList: any) {
  const files = new FormData()
  fileList.forEach((item) => {
    files.append('files', item)
  })
  return request({
    url: '/file/annex/goods',
    method: 'post',
    data: files,
    headers: { 'access-token': useUserStore().token, 'Content-Type': 'multipart/form-data' },
  })
}

// 提示获取是否有重复工单弹窗
export function getUserOrderListWithoutPagination(id: any) {
  return request({
    url: '/user/getUserRelationRepeatOrderList/' + id,
    method: 'post',
    headers: { 'access-token': useUserStore().token, 'Content-Type': 'multipart/form-data' },
  })
}

// 工单附件上传
export function orderAnnexUpload(fileList: any) {
  const files = new FormData()
  fileList.forEach((item) => {
    files.append('files', item)
  })
  return request({
    url: '/file/annex/order',
    method: 'post',
    data: files,
    headers: { 'access-token': useUserStore().token, 'Content-Type': 'multipart/form-data' },
  })
}

// 用户附件上传
export function userAnnexUpload(fileList: any) {
  const files = new FormData()
  fileList.forEach((item) => {
    files.append('files', item)
  })
  return request({
    url: '/file/annex/user',
    method: 'post',
    data: files,
    headers: { 'access-token': useUserStore().token, 'Content-Type': 'multipart/form-data' },
  })
}

// 知识中心附件上传
export function knowledgeAnnexUpload(fileList: any) {
  const files = new FormData()
  fileList.forEach((item) => {
    files.append('files', item)
  })
  return request({
    url: '/file/annex/knowledge',
    method: 'post',
    data: files,
    headers: { 'access-token': useUserStore().token, 'Content-Type': 'multipart/form-data' },
  })
}

// 删除文件
export function deleteFile(data: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/file/delete/',
    method: 'delete',
    headers: token,
    data,
  })
}

// 视频上传
export function videoUpload(fileList: any) {
  const files = new FormData()
  fileList.forEach((item) => {
    files.append('files', item)
  })
  return request({
    url: '/file/video/knowledgeUpload',
    method: 'post',
    data: files,
    headers: { 'access-token': useUserStore().token, 'Content-Type': 'multipart/form-data' },
  })
}
// 编码附件上传
export function codeUpload(fileList) {
  const files = new FormData()
  fileList.forEach((item) => {
    files.append('files', item)
  })
  return request({
    url: '/file/annex/codeUpload',
    method: 'post',
    headers: { 'access-token': useUserStore().token, 'Content-Type': 'multipart/form-data' },
    data: files,
  })
}
// 头像上传
export function userAnnex(files) {
  const file = new FormData()
  file.append('file', files)
  return request({
    url: '/file/annex/avatarUpload',
    method: 'post',
    data: file,
    headers: { 'access-token': useUserStore().token, 'Content-Type': 'multipart/form-data' },
  })
}
//
export function orderVideoUpload(fileList: any) {
  const files = new FormData()
  fileList.forEach((item) => {
    files.append('files', item)
  })
  return request({
    url: '/file/video/orderVideoUpload',
    method: 'post',
    data: files,
    headers: { 'access-token': useUserStore().token, 'Content-Type': 'multipart/form-data' },
  })
}

// 系统附件上传
export function systemAcceUpload(fileList: any) {
  const files = new FormData()
  fileList.forEach((item) => {
    files.append('files', item)
  })
  return request({
    url: '/file/annex/sysUpload',
    method: 'post',
    data: files,
    headers: { 'access-token': useUserStore().token, 'Content-Type': 'multipart/form-data' },
  })
}
// ********************导入类接口************************
// 客户档案导入
export function userExcelImport(file, uuid) {
  const isFile = new FormData()
  isFile.append('file', file)
  return request({
    url: '/import/userExcelImport/' + uuid,
    method: 'post',
    data: isFile,
    headers: { 'access-token': useUserStore().token, 'Content-Type': 'multipart/form-data' },
  })
}
// 工程师资料导入
export function networkEmpImport(file, uuid) {
  const isFile = new FormData()
  isFile.append('file', file)
  return request({
    url: '/import/networkEmpImport/' + uuid,
    method: 'post',
    data: isFile,
    headers: { 'access-token': useUserStore().token, 'Content-Type': 'multipart/form-data' },
  })
}
// 商品资料导入
export function goodsExcelImport(file, type, uuid) {
  const isFile = new FormData()
  isFile.append('file', file)
  return request({
    url: `/import/goodsExcelImport/${type}/${uuid}`,
    method: 'post',
    headers: { 'access-token': useUserStore().token, 'Content-Type': 'multipart/form-data' },
    data: isFile,
  })
}
// 服务商资料导入
export function networkImport(file, uuid) {
  const isFile = new FormData()
  isFile.append('file', file)
  return request({
    url: `/import/networkImport/${uuid}`,
    method: 'post',
    headers: { 'access-token': useUserStore().token, 'Content-Type': 'multipart/form-data' },
    data: isFile,
  })
}
// 编码档案导入
export function codeImport(file, uuid) {
  const isFile = new FormData()
  isFile.append('file', file)
  return request({
    url: `/import/codeImport/${uuid}`,
    method: 'post',
    data: isFile,
    headers: { 'access-token': useUserStore().token, 'Content-Type': 'multipart/form-data' },
  })
}

/**
 * 工单资料导入
 * @param {string} empId - 客服ID
 * @param {string} moduleId - 工单模块ID
 * @param {string} uuid - uuid进度识别码
 * @param {object} file - 文件
 */
export function orderImport(
  uuid: string | number,
  file: UploadRawFile,
) {
  const isFile = new FormData()
  isFile.append('file', file)
  return request({
    url: `/import/orderImport/${uuid}`,
    method: 'post',
    data: isFile,
    headers: { 'access-token': useUserStore().token, 'Content-Type': 'multipart/form-data' },
  })
}
// *********************end**********************
// 商品导出Excel
export function goodsExportExcel(data, type) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/dataExport/goodsExportExcel/' + type,
    method: 'post',
    headers: token,
    data,
    responseType: 'blob',
  })
}
// 导出提现单
export function exportWithdrawToExcel(data) {
  return request({
    url: '/withdraw/exportWithdrawToExcel',
    method: 'post',
    data,
    responseType: 'blob',
  })
}